var 
    gulp      = require('gulp'),
    gutil     = require('gulp-util'),
    bower     = require('bower'),
    concat    = require('gulp-concat'),
    sass      = require('gulp-sass'),
    minifyCss = require('gulp-minify-css'),
    rename    = require('gulp-rename'),
    sh        = require('shelljs'),
    uglify    = require('gulp-uglify'),
    del       = require('del'),
    jshint    = require('gulp-jshint'),
    stylish   = require('jshint-stylish'),
    plumber   = require('gulp-plumber');

var paths     = {
    sass: ['./scss/**/*.scss'],
    base: {
        minPath     :'www/js/*.min.js',
        watchpath   :'www/js/*.js',
        destFile    :'www/dest/*'
    },
    app : {
        source      :'www/js/app.js',
        dest        :'www/dest/',
        destFile    :'app.min.js'
    },
    controller : {
        source      :'www/js/controller/*.js',
        dest        :'www/dest/',
        destFile    :'app.min.js'
    },
    service : {
        source      :'www/js/service/*.js',
        dest        :'www/dest/',
        destFile    :'app.min.js'
  }
};
var count = 1;
gulp.task('watch', ['package'], function() {
    gulp.watch([paths.app.source,paths.controller.source,paths.service.source], ['package']);
});

gulp.task('package', ['jshint','clean', 'concat'])

gulp.task('jshint', function(){
    console.log('*******************************'+count+'******************************************');
    gulp.src([paths.app.source,paths.controller.source,paths.service.source])
        .pipe(jshint())
        .pipe(jshint.reporter(stylish))
})

gulp.task('clean', function(cb){
    del([paths.base.destFile], cb)
})

gulp.task('concat', function(){
    return gulp.src([paths.app.source,paths.controller.source,paths.service.source])
        .pipe(plumber())
        .pipe(concat(paths.app.destFile))
        .pipe(concat(paths.controller.destFile))
        .pipe(concat(paths.service.destFile))
        // .pipe(uglify())
        .pipe(gulp.dest(paths.app.dest))

})

